import store from '@/store'

export default {
  install(Vue, options) {
    Vue.prototype.checkPermission = function(value) {
      if (value && value.length > 0) {
        const routes = store.getters && store.getters.routes
        let hasPermission = false
        // console.log('权限：', routes)
        routes.forEach(item => {
          if (item.path === value) {
            hasPermission = true
          } else {
            if (typeof item.children !== 'undefined' && item.children.length > 0) {
              item.children.forEach(item1 => {
                if (item1.path === value) {
                  hasPermission = true
                } else {
                  if (typeof item1.children !== 'undefined' && item1.children.length > 0) {
                    item1.children.forEach(item2 => {
                      if (item2.path.includes(value)) {
                        hasPermission = true
                      }
                    })
                  }
                }
              })
            }
          }
        })
        return hasPermission
      } else {
        return false
      }
    }
  }
}

